#include <myheader.h>

/* Usage:  */
int main(int argc, char *argv[]){                                  
    char *port="8080";
    char *ip="192.168.74.128";
    int socket_fd=socket(AF_INET,SOCK_STREAM,0);
    struct sockaddr_in sock;
    sock.sin_family=AF_INET;
    sock.sin_addr.s_addr=inet_addr(ip);
    sock.sin_port=htons(atoi(port));
    int ret=connect(socket_fd,(struct sockaddr*)&sock,sizeof(sock));
    ERROR_CHECK(ret,-1,"connect");


    while(1){
        fd_set set;
        FD_ZERO(&set);
        FD_SET(STDIN_FILENO,&set);
        FD_SET(socket_fd,&set);
        select(socket_fd+1,&set,NULL,NULL,NULL);
        
        if(FD_ISSET(STDIN_FILENO,&set)){
            char buf[100]={0};
            read(STDIN_FILENO,buf,sizeof(buf));
            send(socket_fd,buf,sizeof(buf),0);
        }
        if(FD_ISSET(socket_fd,&set)){
            char buf[100]={0};
            ssize_t ret=recv(socket_fd,buf,sizeof(buf),0);
            if(ret==0){
                break;
            }
            printf("buf:%s",buf);

        }

    }
    close(socket_fd);
    
    return 0;
}

